<?php
class Backend_Designer_Sub_Properties extends Backend_Designer_Sub
{
	/**
	 * Get object properties
	 */
	public function listAction()
	{
		$this->_checkLoaded();
		$name = Request::post('object', 'string', false);
		$project = $this->_getProject();
		
		if(!$name || !$project->objectExists($name))
			Response::jsonError($this->_lang->WRONG_REQUEST);

		$data = array();	
		$properties = $project->getObject($name)->getConfig()->__toArray();
		Response::jsonSuccess($properties);
	}
	/**
	 * Set object property
	 */
	public function setpropertyAction(){
		$this->_checkLoaded();
		$object = Request::post('object', 'string', false);
		$property = Request::post('name', 'string', false);
		$value = Request::post('value', 'string', false);
		
		$project = $this->_getProject();
		
		if(!$object || !$project->objectExists($object))
			Response::jsonError($this->_lang->WRONG_REQUEST);
			
		$object = $project->getObject($object);
		if(!$object->isValidProperty($property))
			Response::jsonError();
		
		$object->$property = $value;
		$this->_storeProject();
		Response::jsonSuccess();
	}
}